package com.yupi.apiback.model.enums.interfaceInfo;

import cn.hutool.core.util.StrUtil;
import com.yupi.apiback.common.ErrorCode;
import com.yupi.apiback.exception.BusinessException;

/**
 * @author yanghaifeng
 * @date 2024/1/18 16:21
 */
public enum InterfaceInfoStatusEnum {
    CLOSE("1", "关闭"),
    OPEN("2", "开启");

    InterfaceInfoStatusEnum(String key, String remark) {
        this.key = key;
        this.remark = remark;
    }

    private final String key;
    private final String remark;

    public String getKey() {
        return key;
    }

    public String getRemark() {
        return remark;
    }

    public static InterfaceInfoStatusEnum getKeyEnum(String key) {
        if (StrUtil.isBlank(key)) {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "接口状态枚举不匹配");
        }
        InterfaceInfoStatusEnum[] values = values();
        for (InterfaceInfoStatusEnum value : values) {
            if (value.key.equals(key)) {
                return value;
            }
        }
        throw new BusinessException(ErrorCode.OPERATION_ERROR, "接口状态枚举不匹配");
    }
}
